/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.ucb.game8numbers.service.operator;

import br.com.ucb.game8numbers.bean.Point;
import java.util.Arrays;

/**
 *
 * @author JessicaLuanne
 */
public abstract class Operator {
    private String[][] state;
    private Point source;

    public String[][] realizeOperation()
    {
        if(canOperate())
        {
            Point destination = getDestination();
            String [][] newState = Arrays.copyOf(state, state.length);
            newState[getSource().getLine()][getSource().getColumn()] = getState()[destination.getLine()][destination.getColumn()];
            newState[destination.getLine()][destination.getColumn()] = getState()[getSource().getLine()][getSource().getColumn()];
            return newState;
        }
        return null;
    }

    public abstract Point getDestination();
    public abstract Operator getOppositeOperation();
    public abstract boolean canOperate();

    public Point getSource() {
        return source;
    }

    public void setSource(Point source) {
        this.source = source;
    }

    public String[][] getState() {
        return state;
    }

    public void setState(String[][] state) {
        this.state = state;
    }

}
